package StreamStudy;

import java.io.Serializable;
import java.util.*;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class t2 {
    public static void main(String[] args) {
//        List<Integer> collect = Stream.of(1, 2, 3, 4, 5, 6, 7, 8, 9, 10).filter(item -> item % 2 == 1).collect(Collectors.toList());
//        Set<Integer> collect1 = Stream.of(1, 2, 3, 4, 5, 6, 7, 8, 9, 10).filter(item -> item % 2 == 1).collect(Collectors.toSet());
        ArrayList<String> al = new ArrayList<>();
        al.add("张三,23");
        al.add("李四,24");
        al.add("王五,25");

        Map<String,Integer> mapSI =  al.stream().filter(item -> Integer.parseInt(item.split(",")[1]) >= 24).collect(Collectors.toMap(new Function<String, String>() {
            @Override
            public String apply(String s) {
                return s.split(",")[0];
            }
        }, new Function<String, Integer>() {

            @Override
            public Integer apply(String s) {
                return Integer.parseInt(s.split(",")[1]);
            }
        }));
        System.out.println(mapSI);

    }

    private static void aeee() {
        Long a =  Stream.of(1,2,3,4,5,6,7,7).filter(item->item%2==0).count();
        System.out.println(a);
    }

    private static void aaaa() {
        ArrayList<String> al = new ArrayList<>();
        al.add("林青霞");
        al.add("紫霞");
        al.add("牛魔王");
        al.add("至尊宝");
        al.add("张无忌");
        al.add("张翠山");
        al.add("张良");
        Stream<String> a1 =  al.stream().limit(2).skip(1).distinct();
        System.out.println(a1.count());
    }

    private static void filterDemo() {
        ArrayList<String> al = new ArrayList<>();
        al.add("林青霞");
        al.add("紫霞");
        al.add("牛魔王");
        al.add("至尊宝");
        al.add("张无忌");
        al.add("张翠山");
        al.add("张良");
        Stream<String> stream = al.stream().filter(new Predicate<String>() {
            @Override
            public boolean test(String s) {
                return s.startsWith("张");
            }
        });
        System.out.println(al);
        System.out.println(stream);
        stream.forEach(new Consumer<String>() {
            @Override
            public void accept(String s) {
                System.out.println(s);
            }
        });
    }

    private static void extracted() {
        ArrayList<Integer> arrayList =   new ArrayList<>();
        arrayList.add(1);
        arrayList.add(3);

        HashSet<String> hs = new HashSet<>();
        hs.add("1");
        HashMap<String,String> hm = new HashMap<>();
        hm.put("nihao","value");


        Stream<Serializable> serializableStream = Stream.of(1, 2, 3, "34", new int[]{1, 2, 3}, true, arrayList, hs, hm);
        System.out.println(serializableStream);
        serializableStream.forEach(item-> System.out.println(item));
    }
}
